Misc cleanups
authorMatthias Clasen <mclasen@redhat.com>
Fri, 6 Jan 2023 19:46:47 +0000 (14:46 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 6 Jan 2023 21:50:19 +0000 (16:50 -0500)
Detangle compute_size, among other things.

gdk/wayland/gdkdragsurface-wayland.c
gdk/wayland/gdkpopup-wayland-private.h
gdk/wayland/gdkpopup-wayland.c
gdk/wayland/gdksurface-wayland-private.h
gdk/wayland/gdksurface-wayland.c
gdk/wayland/gdktoplevel-wayland-private.h
gdk/wayland/gdktoplevel-wayland.c

index 5b1fcb6dbf48197183b9ef4cd6b0d2a399a9b0a5..fb42488970cbe4fb7c45578566d79a2e78bc7371 100644 (file)
@@ -71,7 +71,6 @@ gdk_wayland_drag_surface_init (GdkWaylandDragSurface *surface)
 {
 }
 
-
 static gboolean
 gdk_wayland_drag_surface_compute_size (GdkSurface *surface)
 {
@@ -93,9 +92,9 @@ gdk_wayland_drag_surface_compute_size (GdkSurface *surface)
 static void
 gdk_wayland_drag_surface_class_init (GdkWaylandDragSurfaceClass *class)
 {
-  GdkSurfaceClass *impl_class = GDK_SURFACE_CLASS (class);
+  GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (class);
 
-  impl_class->compute_size = gdk_wayland_drag_surface_compute_size;
+  surface_class->compute_size = gdk_wayland_drag_surface_compute_size;
 }
 
 static void
index 94e4ee82abbe8b14c88b0a2e871ad7f9de0619f1..4055aa4943ca3846dab83df7859fca2421bcbd67 100644 (file)
@@ -25,7 +25,6 @@ void update_popup_layout_state (GdkWaylandPopup *wayland_popup,
                                 int              height,
                                 GdkPopupLayout  *layout);
 
-void configure_popup_geometry                     (GdkWaylandPopup *popup);
 void gdk_wayland_surface_configure_popup          (GdkWaylandPopup *popup);
 void frame_callback_popup                         (GdkWaylandPopup *popup);
 void gdk_wayland_popup_hide_surface               (GdkWaylandPopup *popup);
index d0668aa0285a681f967b4ce98c8871ea87f3240c..139204791e99baa52b07096bddbcdbc4dc334a9e 100644 (file)
@@ -350,23 +350,29 @@ frame_callback_popup (GdkWaylandPopup *wayland_popup)
         }
 }
 
-void
-configure_popup_geometry (GdkWaylandPopup *wayland_popup)
+static gboolean
+gdk_wayland_popup_compute_size (GdkSurface *surface)
 {
-  GdkWaylandSurface *wayland_surface = GDK_WAYLAND_SURFACE (wayland_popup);
-  int x, y;
-  int width, height;
+  GdkWaylandPopup *wayland_popup = GDK_WAYLAND_POPUP (surface);
+  GdkWaylandSurface *wayland_surface = GDK_WAYLAND_SURFACE (surface);
 
-  x = wayland_popup->next_layout.x - wayland_surface->shadow_left;
-  y = wayland_popup->next_layout.y - wayland_surface->shadow_top;
-  width =
-    wayland_surface->next_layout.configured_width +
-    (wayland_surface->shadow_left + wayland_surface->shadow_right);
-  height =
-    wayland_surface->next_layout.configured_height +
-    (wayland_surface->shadow_top + wayland_surface->shadow_bottom);
+  if (wayland_surface->next_layout.surface_geometry_dirty)
+    {
+      int x, y, width, height;
 
-  gdk_wayland_surface_move_resize (GDK_SURFACE (wayland_popup), x, y, width, height);
+      x = wayland_popup->next_layout.x - wayland_surface->shadow_left;
+      y = wayland_popup->next_layout.y - wayland_surface->shadow_top;
+      width = wayland_surface->next_layout.configured_width +
+              (wayland_surface->shadow_left + wayland_surface->shadow_right);
+      height = wayland_surface->next_layout.configured_height +
+               (wayland_surface->shadow_top + wayland_surface->shadow_bottom);
+
+      gdk_wayland_surface_move_resize (surface, x, y, width, height);
+
+      wayland_surface->next_layout.surface_geometry_dirty = FALSE;
+    }
+
+  return FALSE;
 }
 
 void
@@ -1070,10 +1076,13 @@ static void
 gdk_wayland_popup_class_init (GdkWaylandPopupClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (class);
 
   object_class->get_property = gdk_wayland_popup_get_property;
   object_class->set_property = gdk_wayland_popup_set_property;
 
+  surface_class->compute_size = gdk_wayland_popup_compute_size;
+
   gdk_popup_install_properties (object_class, 1);
 }
 
index 58746aba80293e1c50715a8aad3811d014674da0..1a260704997c2db669b88b0abb5bd8e319179c61 100644 (file)
@@ -64,9 +64,6 @@ struct _GdkWaylandSurface
 
   GdkRectangle last_sent_window_geometry;
 
-  int saved_width;
-  int saved_height;
-
   struct {
     gboolean is_initial_configure;
     uint32_t serial;
index 93d1620f24b6c94012c5f218a070266cfb8ba546..ee6d3c964b23d91f450fe8bc1decc558daf63315 100644 (file)
@@ -185,8 +185,6 @@ static void
 gdk_wayland_surface_init (GdkWaylandSurface *impl)
 {
   impl->scale = 1;
-  impl->saved_width = -1;
-  impl->saved_height = -1;
 }
 
 void
@@ -213,35 +211,6 @@ gdk_wayland_surface_thaw_state (GdkSurface *surface)
     gdk_wayland_surface_configure (surface);
 }
 
-void
-_gdk_wayland_surface_save_size (GdkSurface *surface)
-{
-  GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
-
-  if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN |
-                        GDK_TOPLEVEL_STATE_MAXIMIZED |
-                        GDK_TOPLEVEL_STATE_TILED))
-    return;
-
-  if (surface->width <= 1 || surface->height <= 1)
-    return;
-
-  impl->saved_width = surface->width - impl->shadow_left - impl->shadow_right;
-  impl->saved_height = surface->height - impl->shadow_top - impl->shadow_bottom;
-}
-
-static void
-_gdk_wayland_surface_clear_saved_size (GdkSurface *surface)
-{
-  GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
-
-  if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN | GDK_TOPLEVEL_STATE_MAXIMIZED))
-    return;
-
-  impl->saved_width = -1;
-  impl->saved_height = -1;
-}
-
 void
 gdk_wayland_surface_update_size (GdkSurface *surface,
                                  int32_t     width,
@@ -393,26 +362,6 @@ configure_drag_surface_geometry (GdkSurface *surface)
                                    impl->scale);
 }
 
-static gboolean
-gdk_wayland_surface_compute_size (GdkSurface *surface)
-{
-  GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
-
-  if (impl->next_layout.surface_geometry_dirty)
-    {
-      if (GDK_IS_WAYLAND_TOPLEVEL (impl))
-        configure_toplevel_geometry (GDK_WAYLAND_TOPLEVEL (surface));
-      else if (GDK_IS_WAYLAND_POPUP (impl))
-        configure_popup_geometry (GDK_WAYLAND_POPUP (surface));
-      else if (GDK_IS_DRAG_SURFACE (impl))
-        configure_drag_surface_geometry (surface);
-
-      impl->next_layout.surface_geometry_dirty = FALSE;
-    }
-
-  return FALSE;
-}
-
 static void
 gdk_wayland_surface_request_layout (GdkSurface *surface)
 {
@@ -1136,8 +1085,6 @@ gdk_wayland_surface_hide_surface (GdkSurface *surface)
   unset_transient_for_exported (surface);
 
   impl->last_sent_window_geometry = (GdkRectangle) { 0 };
-
-  _gdk_wayland_surface_clear_saved_size (surface);
   impl->mapped = FALSE;
 }
 
@@ -1325,26 +1272,25 @@ static void
 gdk_wayland_surface_class_init (GdkWaylandSurfaceClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  GdkSurfaceClass *impl_class = GDK_SURFACE_CLASS (klass);
+  GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (klass);
 
   object_class->constructed = gdk_wayland_surface_constructed;
   object_class->dispose = gdk_wayland_surface_dispose;
   object_class->finalize = gdk_wayland_surface_finalize;
 
-  impl_class->hide = gdk_wayland_surface_hide;
-  impl_class->get_geometry = gdk_wayland_surface_get_geometry;
-  impl_class->get_root_coords = gdk_wayland_surface_get_root_coords;
-  impl_class->get_device_state = gdk_wayland_surface_get_device_state;
-  impl_class->set_input_region = gdk_wayland_surface_set_input_region;
-  impl_class->destroy = gdk_wayland_surface_destroy;
-  impl_class->beep = gdk_wayland_surface_beep;
-
-  impl_class->destroy_notify = gdk_wayland_surface_destroy_notify;
-  impl_class->drag_begin = _gdk_wayland_surface_drag_begin;
-  impl_class->get_scale_factor = gdk_wayland_surface_get_scale_factor;
-  impl_class->set_opaque_region = gdk_wayland_surface_set_opaque_region;
-  impl_class->request_layout = gdk_wayland_surface_request_layout;
-  impl_class->compute_size = gdk_wayland_surface_compute_size;
+  surface_class->hide = gdk_wayland_surface_hide;
+  surface_class->get_geometry = gdk_wayland_surface_get_geometry;
+  surface_class->get_root_coords = gdk_wayland_surface_get_root_coords;
+  surface_class->get_device_state = gdk_wayland_surface_get_device_state;
+  surface_class->set_input_region = gdk_wayland_surface_set_input_region;
+  surface_class->destroy = gdk_wayland_surface_destroy;
+  surface_class->beep = gdk_wayland_surface_beep;
+
+  surface_class->destroy_notify = gdk_wayland_surface_destroy_notify;
+  surface_class->drag_begin = _gdk_wayland_surface_drag_begin;
+  surface_class->get_scale_factor = gdk_wayland_surface_get_scale_factor;
+  surface_class->set_opaque_region = gdk_wayland_surface_set_opaque_region;
+  surface_class->request_layout = gdk_wayland_surface_request_layout;
 }
 
 /* }}} */
index b79d8fff6e320daa754e32d6743e6921780dfc39..4dc87c7b6f4f0b361b4223b9be57ab27754a7b79 100644 (file)
@@ -20,7 +20,6 @@
 
 gboolean gdk_wayland_toplevel_is_exported (GdkWaylandToplevel *wayland_toplevel);
 
-void configure_toplevel_geometry                  (GdkWaylandToplevel *toplevel);
 void gdk_wayland_surface_create_xdg_toplevel      (GdkWaylandToplevel *toplevel);
 void gdk_wayland_surface_configure_toplevel       (GdkWaylandToplevel *toplevel);
 void gdk_wayland_toplevel_sync_parent             (GdkWaylandToplevel *toplevel);
index a73ecb3d07337fd1b0b81775b2310f98769683b7..c198bd04614b5f4a06e2b8c55901f5ef431580e4 100644 (file)
 
 #define MAX_WL_BUFFER_SIZE (4083) /* 4096 minus header, string argument length and NUL byte */
 
-/* {{{ Utilities */
-
-static gboolean
-is_realized_shell_surface (GdkWaylandSurface *impl)
-{
-  return (impl->display_server.xdg_surface ||
-          impl->display_server.zxdg_surface_v6);
-}
-
-/* }}} */
 /* {{{ GdkWaylandToplevel definition */
 
 /**
@@ -132,6 +122,9 @@ struct _GdkWaylandToplevel
     GdkToplevelState set_flags;
   } initial_state;
 
+  int saved_width;
+  int saved_height;
+
   GdkToplevelLayout *layout;
   int bounds_width;
   int bounds_height;
@@ -159,6 +152,46 @@ G_DEFINE_TYPE_WITH_CODE (GdkWaylandToplevel, gdk_wayland_toplevel, GDK_TYPE_WAYL
                          G_IMPLEMENT_INTERFACE (GDK_TYPE_TOPLEVEL,
                                                 gdk_wayland_toplevel_iface_init))
 
+/* }}} */
+/* {{{ Utilities */
+
+static gboolean
+is_realized_shell_surface (GdkWaylandSurface *impl)
+{
+  return (impl->display_server.xdg_surface ||
+          impl->display_server.zxdg_surface_v6);
+}
+
+static void
+gdk_wayland_toplevel_save_size (GdkWaylandToplevel *toplevel)
+{
+  GdkSurface *surface = GDK_SURFACE (toplevel);
+  GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (toplevel);
+
+  if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN |
+                        GDK_TOPLEVEL_STATE_MAXIMIZED |
+                        GDK_TOPLEVEL_STATE_TILED))
+    return;
+
+  if (surface->width <= 1 || surface->height <= 1)
+    return;
+
+  toplevel->saved_width = surface->width - impl->shadow_left - impl->shadow_right;
+  toplevel->saved_height = surface->height - impl->shadow_top - impl->shadow_bottom;
+}
+
+static void
+gdk_wayland_toplevel_clear_saved_size (GdkWaylandToplevel *toplevel)
+{
+  GdkSurface *surface = GDK_SURFACE (toplevel);
+
+  if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN | GDK_TOPLEVEL_STATE_MAXIMIZED))
+    return;
+
+  toplevel->saved_width = -1;
+  toplevel->saved_height = -1;
+}
+
 /* }}} */
 /* {{{ Toplevel implementation */
 
@@ -190,6 +223,8 @@ gdk_wayland_toplevel_hide_surface (GdkWaylandToplevel *toplevel)
   toplevel->last_sent_geometry_hints.min_height = 0;
   toplevel->last_sent_geometry_hints.max_width = 0;
   toplevel->last_sent_geometry_hints.max_height = 0;
+
+  gdk_wayland_toplevel_clear_saved_size (toplevel);
 }
 
 static gboolean
@@ -302,10 +337,10 @@ gdk_wayland_toplevel_sync_title (GdkWaylandToplevel *toplevel)
     }
 }
 
-void
-configure_toplevel_geometry (GdkWaylandToplevel *wayland_toplevel)
+static gboolean
+gdk_wayland_toplevel_compute_size (GdkSurface *surface)
 {
-  GdkSurface *surface = GDK_SURFACE (wayland_toplevel);
+  GdkWaylandToplevel *wayland_toplevel = GDK_WAYLAND_TOPLEVEL (surface);
   GdkWaylandSurface *wayland_surface = GDK_WAYLAND_SURFACE (wayland_toplevel);
   GdkDisplay *display = gdk_surface_get_display (surface);
   int bounds_width, bounds_height;
@@ -314,6 +349,9 @@ configure_toplevel_geometry (GdkWaylandToplevel *wayland_toplevel)
   GdkGeometry geometry;
   GdkSurfaceHints mask;
 
+  if (!wayland_surface->next_layout.surface_geometry_dirty)
+    return FALSE;
+
   if (wayland_toplevel->has_bounds)
     {
       bounds_width = wayland_toplevel->bounds_width;
@@ -406,6 +444,10 @@ configure_toplevel_geometry (GdkWaylandToplevel *wayland_toplevel)
                                   &width, &height);
       gdk_wayland_surface_update_size (surface, width, height, wayland_surface->scale);
     }
+
+  wayland_surface->next_layout.surface_geometry_dirty = FALSE;
+
+  return FALSE;
 }
 
 void
@@ -460,8 +502,8 @@ gdk_wayland_surface_configure_toplevel (GdkWaylandToplevel *wayland_toplevel)
    */
   if (saved_size && !fixed_size && was_fixed_size)
     {
-      width = wayland_surface->saved_width;
-      height = wayland_surface->saved_height;
+      width = wayland_toplevel->saved_width;
+      height = wayland_toplevel->saved_height;
     }
 
   if (width > 0 && height > 0)
@@ -471,7 +513,7 @@ gdk_wayland_surface_configure_toplevel (GdkWaylandToplevel *wayland_toplevel)
           wayland_toplevel->next_layout.should_constrain = TRUE;
 
           /* Save size for next time we get 0x0 */
-          _gdk_wayland_surface_save_size (surface);
+          gdk_wayland_toplevel_save_size (wayland_toplevel);
         }
       else if (is_resizing)
         {
@@ -783,6 +825,8 @@ gdk_wayland_toplevel_init (GdkWaylandToplevel *toplevel)
 {
   toplevel->initial_fullscreen_output = NULL;
   toplevel->shortcuts_inhibitors = g_hash_table_new (NULL, NULL);
+  toplevel->saved_width = -1;
+  toplevel->saved_height = -1;
 }
 
 static void
@@ -1238,11 +1282,14 @@ static void
 gdk_wayland_toplevel_class_init (GdkWaylandToplevelClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (class);
 
   object_class->get_property = gdk_wayland_toplevel_get_property;
   object_class->set_property = gdk_wayland_toplevel_set_property;
   object_class->finalize = gdk_wayland_toplevel_finalize;
 
+  surface_class->compute_size = gdk_wayland_toplevel_compute_size;
+
   gdk_toplevel_install_properties (object_class, 1);
 }
 
@@ -1302,7 +1349,7 @@ gdk_wayland_toplevel_maximize (GdkToplevel *toplevel)
   if (GDK_SURFACE_DESTROYED (surface))
     return;
 
-  _gdk_wayland_surface_save_size (surface);
+  gdk_wayland_toplevel_save_size (wayland_toplevel);
 
   if (is_realized_toplevel (wayland_surface))
     {
@@ -1371,7 +1418,7 @@ gdk_wayland_toplevel_fullscreen_on_monitor (GdkWaylandToplevel *wayland_toplevel
   if (GDK_SURFACE_DESTROYED (surface))
     return;
 
-  _gdk_wayland_surface_save_size (surface);
+  gdk_wayland_toplevel_save_size (wayland_toplevel);
 
   if (is_realized_toplevel (wayland_surface))
     {
@@ -1408,7 +1455,7 @@ gdk_wayland_toplevel_fullscreen (GdkWaylandToplevel *wayland_toplevel)
 
   wayland_toplevel->initial_fullscreen_output = NULL;
 
-  _gdk_wayland_surface_save_size (surface);
+  gdk_wayland_toplevel_save_size (wayland_toplevel);
 
   if (is_realized_toplevel (wayland_surface))
     {